package com.tobby.camelinaction.intercepter;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.processor.DelegateAsyncProcessor;
import org.apache.camel.spi.InterceptStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyIntercepter implements InterceptStrategy {

	private static final Logger LOG = LoggerFactory.getLogger(MyIntercepter.class);

	@Override
	public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition,
			Processor target, Processor nextTarget) throws Exception {
		return new DelegateAsyncProcessor(new Processor() {

			@Override
			public void process(Exchange exchange) throws Exception {
				LOG.info("Before the processor...");
				target.process(exchange);
				LOG.info("After the processor...");
			}
		});
	}

}
